# 使用官方Alpine基础镜像(3.18版本)
FROM alpine:3.18

# 配置国内镜像源
RUN echo "https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.18/main" > /etc/apk/repositories && \
    echo "https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.18/community" >> /etc/apk/repositories && \
    echo "https://mirrors.tuna.tsinghua.edu.cn/alpine/edge/community" >> /etc/apk/repositories && \
    apk update --no-cache

# 安装基础依赖
RUN apk add --no-cache \
    ruby ruby-dev ruby-json ruby-irb \
    build-base linux-headers \
    tzdata ca-certificates \
    ruby-etc \
    libstdc++

# 配置Ruby国内源
RUN gem sources --add https://mirrors.tuna.tsinghua.edu.cn/rubygems/ --remove https://rubygems.org/ && \
    gem install bundler --no-document

# 安装指定版本的Fluentd及必要插件
RUN gem install fluentd -v 1.16.0 --no-document && \
    gem install fluent-plugin-record-modifier --no-document && \
    gem install fluent-plugin-kafka -v 0.19.0 --no-document

# 创建配置目录和日志目录
RUN mkdir -p /fluentd/etc /fluentd/plugins /fluentd/log

# 开放Fluentd端口(24224/TCP+UDP)
EXPOSE 24224 24224/udp

# 启动命令(使用环境变量指定的配置文件)
CMD ["fluentd", "-c", "/fluentd/etc/fluentd.conf", "-p", "/fluentd/plugins"]